package com.pkx.cloud.fse7.dms.splitview.service.impl;

import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.pkx.cloud.fse7.dms.splitview.entity.RpDmsSplitGrantReadView;
import com.pkx.cloud.fse7.dms.splitview.repo.RpDmsSplitGrantReadViewMapper;
import com.pkx.cloud.fse7.dms.splitview.service.RpDmsSplitGrantReadViewService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Objects;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;

/**
 *  服务实现类
 *
 * @author chenwg
 * @since 2020-10-15
 */
@Service
public class RpDmsSplitGrantReadViewServiceImpl extends ServiceImpl<RpDmsSplitGrantReadViewMapper, RpDmsSplitGrantReadView> implements RpDmsSplitGrantReadViewService {

    /**
     * 分页列表
     *
     * @param
     * @return
     */
    @Override
    public Page<RpDmsSplitGrantReadView> pageList(Page page, String startEndtime,String endEndTime,String startBegainTime,String endBegainTime,String readName,String address,String staffName,String tokenId) throws ParseException {
        SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date startTime1=new Date();
        Date startTime2=new Date();
        Date endTime1=new Date();
        Date endTime2=new Date();
        if(StringUtils.isNotBlank(startEndtime)&&StringUtils.isNotBlank(endEndTime)){
            startTime1= sdf.parse(startEndtime);
            endTime1= sdf.parse(endEndTime);
        }
        if(StringUtils.isNotBlank(startBegainTime)&&StringUtils.isNotBlank(endBegainTime)){
            startTime2= sdf.parse(startBegainTime);
            endTime2= sdf.parse(endBegainTime);
        }
        LambdaQueryWrapper<RpDmsSplitGrantReadView> lambdaQueryWrapper = Wrappers.lambdaQuery(RpDmsSplitGrantReadView.class)
                //截止时间
                .between(StringUtils.isNotBlank(startEndtime)&&StringUtils.isNotBlank(endEndTime),RpDmsSplitGrantReadView::getEndDate,startTime1,endTime1)
                //开始时间
                .between(StringUtils.isNotBlank(startBegainTime)&&StringUtils.isNotBlank(endBegainTime),RpDmsSplitGrantReadView::getBeginDate,startTime2,endTime2)
                //读头名称
                .like(StringUtils.isNotBlank(readName),RpDmsSplitGrantReadView::getReadName,readName)
                //家庭住址
                .like(StringUtils.isNotBlank(address),RpDmsSplitGrantReadView::getAddress,address)
                //人员名称
                .like(StringUtils.isNotBlank(staffName),RpDmsSplitGrantReadView::getStaffName,staffName)
                //凭证号
                .like(StringUtils.isNotBlank(tokenId),RpDmsSplitGrantReadView::getTokenId,tokenId);

        return page(page, lambdaQueryWrapper);
    }

    /**
     * 列表查询
     *
     * @param rpDmsSplitGrantReadView
     * @return
     */
    @Override
    public List<RpDmsSplitGrantReadView> listByEntity(RpDmsSplitGrantReadView rpDmsSplitGrantReadView) {
        LambdaQueryWrapper<RpDmsSplitGrantReadView> lambdaQueryWrapper = Wrappers.lambdaQuery(RpDmsSplitGrantReadView.class);
        return list(lambdaQueryWrapper);
    }
}
